package cn.trigram.validation.annotation;

import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.ElementType.PARAMETER;
import static java.lang.annotation.ElementType.TYPE_USE;
import static java.lang.annotation.RetentionPolicy.RUNTIME;

import cn.trigram.validation.annotation.validator.OracleNumberForBigDecimalValidator;
import cn.trigram.validation.annotation.validator.OracleNumberForBigIntegerValidator;
import cn.trigram.validation.annotation.validator.OracleNumberForDoubleValidator;
import cn.trigram.validation.annotation.validator.OracleNumberForIntegerValidator;
import cn.trigram.validation.annotation.validator.OracleNumberForLongValidator;
import cn.trigram.validation.annotation.validator.OracleNumberForStringValidator;
import java.lang.annotation.Documented;
import java.lang.annotation.Repeatable;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
import javax.validation.Constraint;
import javax.validation.Payload;

/**
 * 对应Oracle的Number类型的字段数值校验。
 *
 * @version 1.0.0
 * @date 2022/08/04 09:11:06
 * @since 1.0.0
 */
@Target({FIELD, METHOD, PARAMETER, ANNOTATION_TYPE, TYPE_USE})
@Retention(RUNTIME)
@Constraint(validatedBy = {
        OracleNumberForStringValidator.class,
        OracleNumberForLongValidator.class,
        OracleNumberForBigDecimalValidator.class,
        OracleNumberForBigIntegerValidator.class,
        OracleNumberForDoubleValidator.class,
        OracleNumberForIntegerValidator.class
})
@Documented
@Repeatable(OracleNumberCheck.List.class)
public @interface OracleNumberCheck {

    String message() default "{gf.util.validation.OracleNumberCheck.message}";

    Class<?>[] groups() default {};

    Class<? extends Payload>[] payload() default {};

    /**
     * 精度值，对应Oracle Number 类型的第一个参数.
     * 表示从左边第一个不为0的数开始算起.
     * <br/>
     * 1 <= p <=38
     * <b>必须大于0</b>
     *
     * @return int
     */
    int precision();

    /**
     * 小数点的前后的位数，对应Oracle Number 类型的第二个参数。
     * <br/>
     * 可为负数，负数表示小数点左边的scale位；
     * <br/>
     * 如果为负数，那整个数字的有效位数等于 precision + |scale|；
     * 否则数字的有效位等于 precision。
     * <br/>
     * -84 <= s <= 127
     *
     * @return int
     */
    int scale() default 0;

    @Target({FIELD, METHOD, PARAMETER, ANNOTATION_TYPE})
    @Retention(RUNTIME)
    @Documented
    @interface List {
        OracleNumberCheck[] value();
    }
}
